<template>
  <div class="c-h c-w100 c-ph48 c-pt60">
    <img :src="$addXossFilter(shareLogo, require('../../../assets/defult_head.png'))" class="c-ww100 c-hh100 c-brp50 c-bd1 c-center" />
    <div class="c-fs30 c-mt10 c-textAlign-c">{{companyName}}</div>
    <div class="c-mt40 c-mb20 line"></div>
    <div class="c-fs24 c-fc-xblack c-mt20">即将登陆{{companyName}}，请确认本人操作</div>
    <div class="c-fs20 c-fc-gray c-mt10 c-mb20">使用您的账号登录该应用</div>
    <div class="c-bg-mgreen c-fc-white c-fs30 c-pv24 c-w100 c-br6 c-textAlign-c c-mt40" @click="pcLogin">确认登录</div>
    <div class="c-fc-xblack c-bg-sgray c-bd1-mgray c-fs30 c-pv24 c-w100 c-br6 c-textAlign-c c-mt20" @click="closeWindow">取消登录</div>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js"
export default {
  name: 'RenewalsLogin',
  components: {

  },
  props: [],
  beforeCreate() {

  },
  data() {
    return {
      shareLogo: localStorage.getItem("shareLogo"),
      companyName: localStorage.getItem("mpName"),
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      sess: ''
    }
  },
  created() {
    //pc端扫描二维码进行登录
    setDocumentTitle("微信登录");// eslint-disable-line
    this.sess = this.$route.query.sess;
    this.$store.commit('updateLoadingStatus', {
      isLoading: false
    });
  },
  mounted() {

  },
  computed: {

  },
  watch: {

  },
  methods: {
    pcLogin() {
      if (this.$route.query.liveId) {
        this.liveLogin();
      } else {
        this.pcwxLogin();
      }
    },
    liveLogin() {
      let url = `${global.apiurl}liveFlow/checkManager/${this.$route.query.liveId}`;
      utilJs.getMethod(url, res => {
        if (res.status == 0) {
          this.$showCjToast({
            text: "你不是管理员或讲师身份，无法登录！",
            type: "warn",
          });
        } else {
          this.closeWindow();
        }
      }, failRes => {
        this.$showCjToast({
          text: "登录失败，请重新扫码登录！",
          type: "warn",
        });
      });
    },
    pcwxLogin: function () {
      this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
      //通过host的不同，向后台请求时链接不同
      var href = this.companyAuth ? this.companyAuth.domain : 'pccs.myckjr.com';
      var aurl = href == "pccs.myckjr.com" ? "kpapi-cs.ckjr001.com" : (href.indexOf("ckformal") != -1 ? "formalapi.ckjr001.com" : "kpapiop.ckjr001.com");
      let $this = this;
      utilJs.postMethod(
        "https://" + aurl + "/api/pc/login/qrcodeLogin",
        {
          sess: this.sess,
          c: localStorage.getItem('companyId'),
          u: localStorage.getItem('userId'),
          t: localStorage.getItem('token')
        },
        function (res) {
          $this.closeWindow();
        },
        function () {
          $this.$showCjToast({
            text: "登录失败，请重新扫码登录！",
            type: "warn",
          });
        }
      );
    },
    //确认登录后自动关闭当前页面
    closeWindow: function (event) {
      window.WeixinJSBridge.call('closeWindow');
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.line {
  height: 1px;
  background-color: #999;
  width: 100%;
}
</style>
